package cn.itcast.mq.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class SpringRabbitListener {

//    @RabbitListener(queues = "simple.queue")
//    public void listenSimpleQueue(String msg) {
//        System.out.println("消费者接收到消息：" + msg);
//        System.out.println("开始消费！");
//        System.out.println(1/0);
//        System.out.println("消费完成！");
//    }
//
//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue(name = "dl.queue", durable = "true"),
//            exchange = @Exchange(name = "dl.direct"),
//            key = "dl"
//    ))
//    public void listenDlQueue(String msg) {
//        log.info("消费者接收到了 dl.queue 的延迟消息！msg=" + msg);
//    }
//
//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue(name = "delay.queue", durable = "true"),
//            exchange = @Exchange(name = "delay.direct", delayed = "true"),
//            key = "delay"
//    ))
//    public void listenDelayExchange(String msg) {
//        log.info("消费者接收到了 delay.queue 的延迟消息！msg=" + msg);
//    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "dl.queue", durable = "true"),
            exchange = @Exchange(name = "dl.direct"),
            key = "dl"
    ))
    public void listenDlQueue(String msg) {
        log.info("消费者收到死信消息！msg=" + msg);
    }

//    @RabbitListener(bindings = @QueueBinding(
//        value = @Queue(name = "delay.queue", durable = "true"),
//            exchange = @Exchange(name = "delay.direct", delayed = "true"),
//            key = "delay"
//    ))
//    public void listenDelayExchange(String msg) {
//        log.info("消费者接收到到了延迟消息！msg=" + msg);
//    }
//
//    @RabbitListener(queuesToDeclare = @Queue(
//        name = "lazy.queue",
//            durable = "true",
//            arguments = @Argument(name = "x-queue-mode", value = "lazy")
//    ))
//    public void listenLazyQueue(String msg) {
//        log.info("消费者接收到了惰性队列的消息! msg=" + msg);
//    }

}

